Dreamweaver Article

Implementing User Authentication


Table of Contents

  1. Introduction
  2. Setting Up The Site
  3. User Authentication as a Web Application
  4. Introducing Sessions and Session Variables
  5. Implementing Registration
  6. Implementing Log-on
  7. Enabling Sessions With Application.cfm (ColdFusion Only)
  8. Restricting Access to Pages
  9. Implementing Log Out

User Authentication as a Web Application

Before jumping in and starting to develop an application, you should understand exactly what your goals are and how it's all going to work. Users can only access restricted pages once they've successfully logged in. A database holds all the user profiles—including the usernames and passwords—of all the registered users.

Users must register at the site before they can log in. More specifically, users must have a profile in the database. The database in this tutorial contains only one table, a users table, which contains a half dozen or so profiles. To register, users fill out a web form, which inserts their registration information, including a username and password, into the database, thus creating the profile. In the event that a user chooses an already existing username, the registration fails, and redirects the user to a page that tells him that the name isn't available. Once registered, a user can log in.

To log in, a user supplies a username and password combination, again in a web form. ASP, ColdFusion, or PHP queries the database to see if any records contain both the username and the password together. If it does, the log-in is successful, and the application flags the user as having logged in successfully (more on that in a moment). Once flagged, the user can access any number of restricted pages; that is, a user only has to log in once per site. If there are no records with both the username and password, the log-on fails, and the application redirects the user to a page that indicates that the log-on failed.

Once logged in, users can also log out by clicking a link. Once logged out, the application redirects them to a page that indicates their logged out state.

The following diagram shows the layout of the site relative to this login framework. Solid lines represent the movement of the user through the site. Dashed lines represent the exchange of data between pages and the database.

The login framework

Figure 1. The login framework

Now that you understand the basics of the framework, you might wonder how the pages with restricted access determine whether the user logged in, and therefore whether to display the restricted content. Each restricted page has a script at the top that verifies whether the user logged in successfully, and if so, processes and displays the page. If the user has not logged in, the application typically redirect the user to a page that enables log-on; the restricted page never loads.